package com.yuhs.zixing.study.design.pattern.dp001.principle.p05.open.close;

/**
 * @description
 * @author: yuhs
 * @date 2022/3/26 下午4:57
 */
public class OpenCloseDemo002 {

    public static void main(String[] args) {
        GraphicEditor002 graphicEditor = new GraphicEditor002();
        graphicEditor.drawShape(new Rectangle002());
        graphicEditor.drawShape(new Circle002());
        graphicEditor.drawShape(new Triangle002());
    }
}

/**
 * 这是一个用于绘图的类
 */
class GraphicEditor002 {

    /**
     * 接受shape 对象，然后根据type 来绘画不同图形
     */
    public void drawShape(Shape002 shape) {
        shape.draw();
    }
}

abstract class Shape002 {
    int mType;

    public abstract void draw();
}

/**
 * 矩形
 */
class Rectangle002 extends Shape002 {
    Rectangle002() {
        super.mType = 1;
    }

    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

/**
 * 圆形
 */
class Circle002 extends Shape002 {
    Circle002() {
        super.mType = 2;
    }

    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

/**
 * 三角形
 */
class Triangle002 extends Shape002 {
    Triangle002() {
        super.mType = 3;
    }

    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}

